package com.zhihaoliang.coroutine.buss.flow.func

import com.zhihaoliang.coroutine.util.log
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch

/**
 * @author 支豪亮
 * @date 2022/10/24 16:00
 * @des 流的顺序操作的
 */
object FlowSequential {

    fun onSequential(mainScope: CoroutineScope) = mainScope.launch {
        (1..5).asFlow()
            .filter {
                log("Filter $it")
                it % 2 == 0
            }
            .map {
                log("Map $it")
                "string $it"
            }.collect {
                log("Collect $it")
            }
    }
}